package com.mes.web.controller.hpf;

import java.text.ParseException;
import java.text.SimpleDateFormat;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mes.entity.hpf.ReceiptAmount;
import com.mes.service.hpf.ReceiptAmountService;

import net.sf.json.JSONObject;

@Controller
@RequestMapping("/hpf")
public class ReceiptAmountController {

	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
	@Resource
	public ReceiptAmountService receiptAmountService;
    
    //添加对账信息
    @RequestMapping("/addReceiptAmount")
    public @ResponseBody int addReceiptAmount(@RequestBody Object obj) throws ParseException {
    	int addIsSuccess = 0;
    	SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
    	JSONObject jsonObject = JSONObject.fromObject(obj);
    	ReceiptAmount receiptAmount = new ReceiptAmount();
    	receiptAmount.setCustomerId((String)jsonObject.get("customerId"));
    	receiptAmount.setReceiptDate((new java.sql.Date(simpleDateFormat.parse((String)jsonObject.get("receiptDate")).getTime())));
        receiptAmount.setAmount(Float.parseFloat((String)jsonObject.get("amount")));
        addIsSuccess = receiptAmountService.addReceiptAmount(receiptAmount);
    	return addIsSuccess;
    }
	
}
